package com.acme.bankapp.domain.bank.account;

import com.acme.bankapp.domain.bank.exception.OverDraftLimitExceededException;

/**
 * This class implements {@link AbstractAccount} interface for clients with overdraft
 *
 * @author Alexander Kotov
 */

public class CheckingAccount extends AbstractAccount {

    private final double overdraft;

    public CheckingAccount(double balance, double overdraft) throws IllegalArgumentException{
        super(balance);
        if (overdraft < 0) {
            throw new IllegalArgumentException("Negative overdraft");
        }
        this.overdraft = overdraft;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void withdraw(double amount) throws OverDraftLimitExceededException {
        if (balance + overdraft >= amount) {
            balance -= amount;
        }
        else {
            throw new OverDraftLimitExceededException(this);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public double getMaximumAmountToWithdraw() {
        return balance + overdraft;
    }
}
